<template>
  <Card :dis-hover="true" :title="$route.meta.title">
    <Table :columns="tableColumns" :data="tablePager.items" :loading="tableLoading" />

    <Page :current="tablePager.current" :total="tablePager.total_items" :page-size="tablePager.limit" show-total @on-change="onChangePage"></Page>
  </Card>
</template>

<script>
  import { Card, Page, Table } from 'iview';
  import staffApi from '@/api/staff/index';

  export default {
    components: {
      [Card.name]: Card,
      [Page.name]: Page,
      [Table.name]: Table
    },
    data() {
      return {
        tableLoading: false,
        tablePager: {
          current: 1,
          limit: 10
        },
        tableColumns: [
          {title: 'ID', align: 'center', render: (h, params) => { return h('span', params.row.staff.id); }},
          {title: '账号', align: 'center', render: (h, params) => { return h('span', params.row.staff.account); }},
          {title: '角色', align: 'center', render: (h, params) => { return h('span', params.row.staff_acl_roles.description); }}
        ]
      }
    },
    methods: {
      onChangePage(current) {
        this.tablePager.current = current;
        this.getData();
      },
      getData() {
        this.tableLoading = true;
        staffApi.pager(this.tablePager.limit, this.tablePager.current).then((data) => {
          if(data.pager) { this.tablePager = data.pager; }
          this.tableLoading = false;
        });
      }
    },
    created() {
      this.getData();
    }
  }
</script>
